package com.xsky.validator
{
	import mx.validators.ValidationResult;
	import mx.validators.Validator;

	public class IdCardValidator extends Validator
	{
		private var idInValid:String = "身份证号码格式错误";
		private var idInValidCode:String = '10002';
		protected var idReg:RegExp = /^((11|12|13|14|15|21|22|23|31|32|33|34|35|36|37|41|42|43|44|45|46|50|51|52|53|54|61|62|63|64|65)[0-9]{4})(([1|2][0-9]{3}[0|1][0-9][0-3][0-9][0-9]{3}[X0-9])|([0-9]{2}[0|1][0-9][0-3][0-9][0-9]{3}))$/
		
		public function IdCardValidator()
		{
			super();
		}
		public function get idInvalidError():String
		{
			return idInValid;
		}
		public function set idInvalidError(invalidStr:String):void
		{
			this.idInValid = invalidStr;
		}
		public function doIdValidation(validator:IdCardValidator, value:Object, baseField:String):Array
		{
			var rs:Array = [];
			if(!idReg.test(String(value)))
			{
				rs.push(new ValidationResult(true, baseField,validator.idInValidCode, validator.idInValid));
			}
			return rs;
		}
		override protected function doValidation(value:Object):Array
		{
			var rs:Array = super.doValidation(value);
			var val:String = value?String(value):'';
			if(rs.length>0||(val.length==0)&&!required)
			{
				return rs;
			}
			return doIdValidation(this,value,null);
		}
	}
}